<?php
include_once ("../controller/functions.php"); 

$user = new User();

if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	header("location:login_r.php");

}

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{ 
$login = $user->check_login(htmlspecialchars($_POST['emailusername'],ENT_QUOTES), $_POST['password'], $_POST['user_type']);
$login = true;
if ($login) 
{
	switch($_SESSION['user_type']):
	
	case 'admin':			
				$_SESSION['user_type']	 = $user_data['user_type'];
				$_SESSION['userid']		 = $user_data['userid'];
				mysql_query("UPDATE `tblusers` SET lastlogin = NOW() WHERE userid = '$user_data[userid]'");
				include("admin.php");
				break;		
					
	case 'student':
				$_SESSION['user_type']	 = $user_data['user_type'];
				$_SESSION['userid']		 = $user_data['userid'];
				mysql_query("UPDATE `tblusers` SET lastlogin = NOW() WHERE userid = '$user_data[userid]'");
				include("student.php");		
				break;			
				
	case 'teacher':
				$_SESSION['user_type'] = $user_data['user_type'];
				$_SESSION['userid'] = $user_data['userid'];
				mysql_query("UPDATE `tblusers` SET lastlogin = NOW() WHERE userid = '$user_data[userid]'");
				include("teacher.php");
				break;
				
	case '';
				header("location:login_r.php");
				break;			
	endswitch;
} 
else 
{
echo 'Username / password wrong';
}
}
?>
